/*************************************************************************
	> File Name: P8697.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-04-07 16:19:26
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int calc(string &s, string &t) {
    int ans = 0;
    for (int i = 0, j = 0; i < s.size() && j < t.size(); i++) {
        if (s[i] == t[j]) {
            ans++;
            j++;
        }
    }
    return ans;
}

int main() {
    string a, b;
    cin >> a >> b;
    cout << calc(a, b) << endl;
    return 0;
}
